#ifndef CORE_CDEVICEMANAGER_H_
#define CORE_CDEVICEMANAGER_H_

#include <memory>
#include <string>

#include "zlbase/zlbase.h"

#include "defines.h"

class CDeviceManager
{
public:
    static CDeviceManager &Instance();

    bool LoadDeviceConfiguration(const std::string &path = "./config/devices.xml");
    bool SaveDeviceConfiguration(const std::string &path = "./config/devices.xml");
    void LoadZLBasePlugins();

    std::shared_ptr<zl::zlbase::IDevice> GetDevice(const std::string &id);
    std::shared_ptr<zl::zlbase::IDoorControlBoard> GetDoorControlBoard(const std::string &id);
    std::shared_ptr<zl::zlbase::IMonitorControlBoard> GetMonitorControlBoard(const std::string &id);
    std::shared_ptr<zl::zlbase::ITemperatureControlBoard> GetTemperatureControlBoard(const std::string &id);

    ZLDeviceConfig GetDeviceConfig();
    void SetDeviceConfig(const ZLDeviceConfig& device_config);

    void GetDeviceInfo(const std::string id, ZLBaseDevice& device);
    void GetDeviceInfo(const std::string id, ZLPeripheralsDevice& device);
    
    void GetPlugins(std::vector<ZLBasePlugin>& plugins);
    void GetPlugins(int32_t type, std::vector<ZLBasePlugin>& plugins);
    bool GetPluginInfo(const std::string& uuid, ZLBasePlugin& plugin);

protected:
    template <class Factory>
    void create_zlbase_device(const ZLBaseDevice &d, Factory &factory);

private:
    CDeviceManager();
    ~CDeviceManager();

    class CDeviceManagerPrivate;
    CDeviceManagerPrivate *p_;
};

#endif // CORE_CDEVICEMANAGER_H_